package org.jeecg.modules.carRegister.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.carRegister.entity.CarRegister;
import org.jeecg.modules.carRegister.mapper.CarRegisterMapper;
import org.jeecg.modules.carRegister.service.ICarRegisterService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description: 车辆登记
 * @Author: jeecg-boot
 * @Date:   2024-07-25
 * @Version: V1.0
 */
@Service
public class CarRegisterServiceImpl extends ServiceImpl<CarRegisterMapper, CarRegister> implements ICarRegisterService {

    @Override
    public CarRegister getLastByPlateNo(String plateNo) {
        LambdaQueryWrapper<CarRegister> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CarRegister::getPlateNo, plateNo);
        wrapper.eq(CarRegister::getEntryStatus, 0);//未入场的
        wrapper.eq(CarRegister::getRegisterStatus, 1);//审核已通过的
        wrapper.orderByDesc(CarRegister::getCreateTime);
        wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<Map<String, String>> getCount() {
        return baseMapper.getCount();
    }

    @Override
    public CarRegister getOneByPlateNo(String plateNo) {
        LambdaQueryWrapper<CarRegister> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CarRegister::getPlateNo, plateNo);
        wrapper.orderByDesc(CarRegister::getCreateTime);
        wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public CarRegister getLastUnApprovalByPlateNo(String plateNo) {
        LambdaQueryWrapper<CarRegister> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CarRegister::getPlateNo, plateNo);
        wrapper.eq(CarRegister::getEntryStatus, 0);//未入场的
        wrapper.eq(CarRegister::getApprovalStatus, 0);//未审批的
        wrapper.orderByDesc(CarRegister::getCreateTime);
        wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }
}
